/*
   Copyright 2009 Bégaudeau Stéphane

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package faneclipse.builder;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;

/**
 * This class has to visit IResource that do not require a full build.
 * @author BEGAUDEAU stephane
 */
public class FanDeltaVisitor implements IResourceDeltaVisitor {
	
	/**
	 * The constructor.
	 */
	public FanDeltaVisitor() {
		super();
	}

	/**
	 * @param delta The resource.
	 * @return a boolean indicating if we can visit children of that element.
	 * @throws CoreException An exception is created if the FileChecker has a problem.
	 * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
	 */
	public final boolean visit(final IResourceDelta delta) throws CoreException {
		IResource resource = delta.getResource();
		FanFileChecker fileChecker = new FanFileChecker(resource);
		
		switch (delta.getKind()) {
		case IResourceDelta.ADDED:
			// handle added resource
			fileChecker.check();
			break;
		case IResourceDelta.REMOVED:
			// handle removed resource
			fileChecker.check();
			break;
		case IResourceDelta.CHANGED:
			// handle changed resource
			fileChecker.check();
			break;
		default:
			// check anyway...
			fileChecker.check();
			break;
		}
		//return true to continue visiting children.
		return true;
	}

}
